var app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        shirtLists: [],
        is_desc: "",
        loading_show: true
    },
    onLoad: function (options) {
        var that = this;
        var goods_type = options.type;
        this.setData({
            goods_type: goods_type
        })
        if (goods_type) {
            // 页面加载完成之后将筛选的条件清除
            wx.removeStorage({
                key: 'selectParams',
                success: function (res) {

                }
            })
            wx.removeStorage({
                key: 'sign',
                success: function (res) {

                }
            })
        }
    },
    onReady: function () {

    },
    onShow: function () {
        var that = this;
        var goods_type = that.data.goods_type;
        wx.getStorage({
            key: 'sign',
            success: function (res) {
                var data = res.data;
                if (data == "zonghe") {
                    that.zonghe();
                } else if (data == 'update_time') {
                    that.shangxin();
                } else if (data == 'sales_money') {
                    if (this.data.is_desc == "desc") {
                        this.setData({
                            is_desc: "desc",
                            sign: "sales_money"
                        })
                    } else {
                        this.setData({
                            is_desc: "asc",
                            sign: "sales_money"
                        })
                    }
                    that.jiage();
                } else if (data == 'shaixuan') {
                    wx.getStorage({
                        key: 'selectParams',
                        success: function (res) {
                            that.setData({
                                sign: "shaixuan",
                                is_desc: ""
                            })
                            var data = res.data;
                            if (data) {
                                var params = {};
                                params['item_detail'] = data;
                                params['type'] = goods_type;
                                that.init(params)
                            }
                        }
                    })
                }
            },
            fail: function () {
                that.zonghe()
            }
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        var sign = this.data.sign;
        wx.setStorage({
            key: 'sign',
            data: sign
        })
    },
    onShareAppMessage: function () {
        wx.removeStorage({
            key: 'selectParams',
            success: function (res) { },
        })
    },
    onUnload: function () {
        // 页面关闭的时候清除数据

    },
    init: function (params) {
        var that = this;
        wx.request({
            url: app.config() + 'index/getTypeGoods',
            data: params,
            success: function (res) {
                if (res.data.status == 0) {
                    var data = res.data.data;
                    var len = data.length;
                    if (!len) {
                        that.setData({
                            loading_show: false
                        })
                    } else {
                        that.setData({
                            loading_show: true,
                            data: data
                        })
                    }
                } else {
                    that.setData({
                        loading_show: false
                    })
                }

            }
        })
    },//综合
    zonghe: function () {
        var params = {};
        params['type'] = this.data.goods_type;
        params['item_detail'] = { "filterArr": [] };
        this.init(params)
        this.setData({
            sign: "zonghe",
            is_desc: ""
        })
    },//上新
    shangxin: function () {
        var params = {};
        params['order_name'] = "update_time";
        params['item_detail'] = { "filterArr": [] };
        params['type'] = this.data.goods_type;
        this.init(params)
        this.setData({
            sign: "update_time",
            is_desc: ""
        })
    },//价格
    jiage: function () {
        if (this.data.is_desc == "desc") {
            this.setData({
                is_desc: "asc",
                sign: "sales_money"
            })
        } else {
            this.setData({
                is_desc: "desc",
                sign: "sales_money"
            })
        }
        var params = {};
        params['is_desc'] = this.data.is_desc;
        params['order_name'] = "sales_money";
        params['item_detail'] = { "filterArr": [] };
        params['type'] = this.data.goods_type;
        this.init(params)
    },//筛选
    shaixuan: function () {
        var goods_type = this.data.goods_type;
        this.setData({
            sign: "shaixuan",
            is_desc: ""
        })
        var url = "../selected/selected?goods_type=" + goods_type;
        wx.navigateTo({
            url: url
        })
    }
})